//
//  XWTabViewController.m
//  CGWSWW
//
//  Created by lanou3g on 16/8/12.
//  Copyright © 2016年 CXG. All rights reserved.
//

#import "XWTabViewController.h"
#import "XWNavViewController.h"
#import "XWAudioViewController.h"
#import "XWNewsViewController.h"
#import "XWSearchViewController.h"
#import "XWJokeViewController.h"
#import "XWMeViewController.h"
#import "UIImage+XWExtension.h"

@interface XWTabViewController ()

@end

@implementation XWTabViewController
+(void)initialize{
    //设置UITabBarItem的状态下的字体样式
    [[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor],NSFontAttributeName:[UIFont fontWithName:@"AmericanTypewriter-Bold" size:13]} forState:(UIControlStateNormal)];
    [[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor  orangeColor],NSFontAttributeName:[UIFont fontWithName:@"Zapfino" size:13]} forState:(UIControlStateSelected)];
    //设置tabbar背景图片
    [[UITabBar appearance]setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:206 green:206 blue:206 alpha:1]]];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    //加载子视图
    [self addChildViewControllers];
}

-(void)addChildViewControllers{
    [self setUpOneChildViewController:[XWNewsViewController new] image:@"news_deseleted" selectedImage:@"news_seleted" title:@"新闻"];
    [self setUpOneChildViewController:[XWAudioViewController new] image:@"player_deselected" selectedImage:@"player_selected" title:@"影音"];
    [self setUpOneChildViewController:[XWJokeViewController new] image:@"paragraph_deselected" selectedImage:@"paragraph_selected" title:@"趣文"];
    [self setUpOneChildViewController:[XWSearchViewController new] image:@"search_deselected" selectedImage:@"search_selected" title:@"搜索"];
    [self setUpOneChildViewController:[XWMeViewController new] image:@"user_deselected" selectedImage:@"user_selecter" title:@"个人"];
}
//自定义加载子控制器的方法
-(void)setUpOneChildViewController:(UIViewController*)ViewController image:(NSString*)image selectedImage:(NSString*)selectedImage title:(NSString*)title{
    ViewController.title =title;
    ViewController.navigationItem.title = nil;
    if (image.length) {
        //设置tabBarItem的图片(规避渲染的情况发生)
        ViewController.tabBarItem.image =[[UIImage imageNamed:image]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
        ViewController.tabBarItem.selectedImage =[[UIImage imageNamed:selectedImage]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];;
    }
        //添加控制器->子控制器ZDYNavigationController的根控制器
    [self addChildViewController:[[XWNavViewController alloc]initWithRootViewController:ViewController ]];
    
}


@end
